package com.atguigu.yygh.user.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/*==========================================
      时 间:   2022-03-15
      讲 师:   刘  辉
      描 述:   尚硅谷教学团队
 ==========================================*/
@RestController
@RequestMapping("/admin/userinfo")
public class AdminUserInfoController {


    @Autowired
    private UserInfoService userInfoService;

    //用户列表（条件查询带分页）
    @GetMapping("{pageNum}/{limit}")
    public R getUserInfoPageByQueryCondition(@PathVariable Integer pageNum,
                                             @PathVariable Integer limit,
                                             UserInfoQueryVo userInfoQueryVo){


       Page<UserInfo> page = userInfoService.getUserInfoPageByQueryCondition(pageNum,limit,userInfoQueryVo);
       return R.ok().data("page",page);
    }


    //用户列表（条件查询带分页）
    @PutMapping("/lock/{id}/{status}")
    public R lock(@PathVariable Integer id, @PathVariable Integer status){
        userInfoService.lock(id,status);
         return R.ok();
    }
    //认证审批
    @GetMapping("approval/{userId}/{authStatus}")
    public R approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return R.ok();
    }

    //show:
    @GetMapping("/show/{id}")
    public R show(@PathVariable Integer id){
        Map<String,Object> map =userInfoService.show(id);
        return R.ok().data(map);
    }

}
